class RMWeap_SpaceTimeGun extends UTWeapon;

/** Attraction Intensity Multiplier */
var() float					IntensityXplier;

/** Attraction Intensity Multiplier */
var() float					MaxIntensityXplier;

/** How much distance should be between each shot */
var int	SpreadDist;

/** Allow for multiple muzzle flash sockets **FIXME: will become offsets */
var array<name> MuzzleFlashSocketList;

/** Texture of Gun Cast-Bar */
var() Texture CastBarTexture;

/** How much of the load-up timer needs to pass before the weapon will wait to fire on release */
var float WaitToFirePct;

/** This holds the maximum number of shots that can be queued */
var int MaxLoadCount;

/** How much grace at the end of loading should be given before the weapon auto-fires */
var float GracePeriod;

/** Have we hidden any of the ammo sockets from player's view */
var bool bIsAnyAmmoHidden;

/** Skeletal mesh component for the 1st person view of the rocketlauncher */
var UDKSkeletalMeshComponent SkeletonFirstPersonMesh;

/** Holds a list of emitters that make up the muzzle flash */
var array<UTParticleSystemComponent> MuzzleFlashPSCList;

var float                   Timer;

var float MaxChargeTime;
var float ChargeTime;
var float WeaponCharge;

simulated function PlayWeaponAnimation(name Sequence, float fDesiredDuration, optional bool bLoop, optional SkeletalMeshComponent SkelMesh)
{
	if (Mesh != None && Mesh.bAttached)
	{
		Super.PlayWeaponAnimation(Sequence, fDesiredDuration, bLoop, SkelMesh);
	}
}

simulated function DrawCastBar(HUD Hud)
{
	Hud.Canvas.CurX = 350;
	Hud.Canvas.CurY = 500;
	Hud.Canvas.DrawRect(400 * IntensityXplier, 100, CastBarTexture);
}


simulated function FireAmmunition()
{
	if (CurrentFireMode >= bZoomedFireMode.Length || bZoomedFireMode[CurrentFireMode] == 0)
	{
		// if this is the local player, play the firing effects
		PlayFiringSound();
		ConsumeAmmo( CurrentFireMode );
		ProjectileFire();
		NotifyWeaponFired( CurrentFireMode );
		//InvManager.OwnerEvent('FiredWeapon');
	}	
}


simulated state WeaponFiring
{
	simulated function BeginState(Name previousStateName)
	{
		ChargeTime = WorldInfo.TimeSeconds;
		RMPawn(Instigator).BlobIntensity = 0;
		//PlayWeaponAnimation(ChargeAnim, MaxChargeTime);
	}

	simulated function BeginFire(byte FireModeNum)
	{
		Global.BeginFire(FireModeNum);	
	}

	simulated function EndFire(byte FireModeNum)
	{
		RMPawn(Instigator).BlobIntensity = IntensityXplier;
		Global.EndFire(FireModeNum);
		FireAmmunition();
		IntensityXplier = 0.0;
		//PlayWeaponAnimation('WeaponFireAnim', 0.2);
		GotoState('Active');
	}

	simulated function Tick(float deltaTime)
	{
		if (IntensityXplier >= MaxIntensityXplier)
		{
			EndFire(0);
		}
		else
		{
			IntensityXplier = GetPowerPerc();
		}
	}

	simulated event float GetPowerPerc()
	{
		local float p;
		p = (WorldInfo.TimeSeconds - ChargeTime) / MaxChargeTime;
		p = FClamp(P,0.0,1.0);
		return p * 2;
	}

	simulated function DrawWeaponCrosshair( Hud HUD )
	{
		super.DrawWeaponCrosshair(HUD);
		DrawCastBar(HUD);
	}
}

defaultproperties
{
	FireInterval(0)=+0.1 //Blob firing interval
	WeaponFireTypes(0)=EWFT_Projectile
	CastBarTexture="UDKHUD.player_brown"

	IntensityXplier = 0
	MaxIntensityXplier = 1
	MaxChargeTime = 1.0

	WeaponProjectiles(0)=class'RedMatter.RMProj_Blob'
	
	ShotCost(0)=0

	ShouldFireOnRelease(0)=0
	InventoryGroup=2
	GroupWeight=0.5
	AimError=600

	AmmoCount=10000
	LockerAmmoCount=50
	MaxAmmoCount=10000

	IconX=335
	IconY=81
	IconWidth=43
	IconHeight=39
	
	WeaponColor=(R=255,G=255,B=255,A=255)

	Begin Object class=AnimNodeSequence Name=MeshSequenceA
		bCauseActorAnimEnd=true
	End Object

	Begin Object Name=FirstPersonMesh
		SkeletalMesh=SkeletalMesh'WP_LinkGun.Mesh.SK_WP_LinkGun_3P'
		AnimSets(0)=AnimSet'WP_LinkGun.Anims.K_WP_LinkGun_1P_Base'
		Animations=MeshSequenceA
		Scale=0.9
		FOV=60.0
	End Object
	AttachmentClass=class'UTAttachment_Linkgun'

	Begin Object Name=PickupMesh
		SkeletalMesh=SkeletalMesh'WP_LinkGun.Mesh.SK_WP_LinkGun_3P'
	End Object

	WeaponFireSnd(0)=SoundCue'A_Weapon_Link.Cue.A_Weapon_Link_FireCue'

	MuzzleFlashSocket=class'MuzzleFlashSocket'
	MuzzleFlashDuration=0.33
	MuzzleFlashLightClass=class'UTGame.UTRocketMuzzleFlashLight'
}